<%@ page import="com.dao.UserDao" %>
<%@ page import="com.bean.User" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="com.bean.Friends" %>
<%@ page import="com.dao.FriendsDao" %>
<%@ page import="com.bean.Group" %>
<%@ page import="com.dao.GroupDao" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%
  String qq = request.getParameter("qq");
  String groupQQ = request.getParameter("groupQQ");
  String groupName = request.getParameter("groupName");
  UserDao userDao = new UserDao();
  GroupDao groupDao = new GroupDao();
  User user = userDao.findOne(qq);
  PrintWriter writer =response.getWriter();
  int num = groupDao.isEXistGroup(groupQQ);
  if(num!=0){
    writer.write("-1");
  }else {
    Group group = new Group();
    group.setUserId(user.getId());
    group.setName(groupName);
    group.setQq(groupQQ);
    groupDao.saveGroup(group);


    StringBuffer sb = new StringBuffer();
    sb.append("{").append("\"groupQQ\":"+"\""+group.getQq()+"\"").append(",")
            .append("\"groupName\":"+"\""+group.getName()+"\"").append(",")
            .append("\"userId\":"+"\""+group.getUserId()+"\"").append("}");
    writer.write(sb.toString());
  }

  writer.close();
%>